// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tcmdb.rest;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import de.servicezombie.tcmdb.rest.vo.WsListResult;

public class RestTransformerSupport {
	
	public <FROM, TO> void copy(Collection<FROM> from, List<TO> into, Transformer<FROM, TO> transformerStrategy) {
		for (FROM fromItem : from) {
			TO intoItem = transformerStrategy.transform(fromItem);
			into.add(intoItem);
		}
	}
	
	public <FROM, TO> WsListResult<TO> toWsListResult(Collection<FROM> from, Transformer<FROM, TO> transformerStrategy) {		
		List<TO> to = new ArrayList<TO>();
		copy(from, to, transformerStrategy);
		return new WsListResult<TO>(to);
	}

}
